home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / bs941029.tgz / bbsx-941029.tar / bbsx / tell.c < prev    next >
C/C++ Source or Header  |  1994-10-29  |  3KB  |  145 lines

  1. #ifndef __lint
  2. static char rcsid[] = "@(#) $Header: /home/dg1rtf/tcp/bbsx/RCS/tell.c,v 1.1 1994/06/01 22:21:32 dg1rtf Exp $";
  3. #endif
  4.  
  5. #define _HPUX_SOURCE
  6.  
  7. #include <stdio.h>
  8.  
  9. #include <ctype.h>
  10. #include <dirent.h>
  11. #include <errno.h>
  12. #include <fcntl.h>
  13. #include <pwd.h>
  14. #include <signal.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <sys/socket.h>
  18. #include <sys/stat.h>
  19. #include <sys/time.h>
  20. #include <sys/wait.h>
  21. #include <termios.h>
  22. #include <unistd.h>
  23.  
  24. #include "bbs.h"
  25. #include "bbs.hd"
  26.  
  27. static int err_flag;
  28. static FILE *fpbbs;
  29. static FILE *fpsendmail;
  30. static FILE *fbbs;
  31. const struct cmdtable cmdtable[1];
  32.  
  33. /* In rerase.c: */
  34. int main(int argc, char **argv);
  35. static char *get_cmd_from_path(char *path);
  36.  
  37. /*---------------------------------------------------------------------------*/
  38.  
  39. static char *get_cmd_from_path(char *path)
  40. {
  41.  
  42.   char *cp;
  43.   static char tmp[1024];
  44.  
  45.   strcpy(tmp, path);
  46.   cp = strrchr(tmp, '@');
  47.   if (!cp) return "EXIT";
  48.   *cp = 0;
  49.   cp = strrchr(tmp, '@');
  50.   return cp ? (cp + 1) : tmp;
  51. }
  52.  
  53. /*---------------------------------------------------------------------------*/
  54.  
  55.  
  56. int main(int argc, char **argv)
  57. {
  58.   struct index index;
  59.   struct passwd *pw;
  60.   char buffer[4096];
  61.   char buf[4096];
  62.   char command[1024];
  63.   int status;
  64.  
  65.   if (getuid()) {
  66.     pw = getpwnam(bbsadm);
  67.     if(getuid() != pw->pw_uid) {
  68.       perror("permission denied");
  69.       return 1;
  70.     }
  71.   }    
  72.  
  73.   if (chdir(WRKDIR)) {
  74.     mkdir(WRKDIR, 0755);
  75.     if(chdir(WRKDIR)) halt();
  76.   }  
  77.  
  78.   read_config();
  79.  
  80.  
  81.   pw = getpwnam(telluser);
  82.   if (!(pw)) { 
  83.     perror("cann't find such user");
  84.     return 1;
  85.   }
  86.       
  87.   if ((fdindex = open(INDEXFILE, O_RDWR, 0644)) < 0) return 1;
  88.   
  89.   unlink("/tmp/bbs_tell");
  90.   
  91.   for (; ; ) {
  92.     if (read(fdindex, (char *) &index, sizeof(index)) != sizeof(index)) goto stop;
  93.     if (!(index.flags & DELETED)) {
  94.       if (!strcmp(index.to,"T") && !strcmp(index.at,Myhostname)) {
  95.          if (fork() == 0) {
  96.            setuid(pw->pw_uid);
  97.            fpbbs=popen("exec bbs > /tmp/bbs_tell","w");
  98.            if(!fpbbs) {
  99.              puts("cannot open bbs");
  100.              close(fdindex);
  101.              return 1;
  102.            }
  103.            fprintf(fpbbs,"%s\n",get_cmd_from_path(index.subject));
  104.            fprintf(fpbbs,"QUIT\n");
  105.            pclose(fpbbs);
  106.            exit (0);
  107.          } else
  108.            wait(&status); 
  109.  
  110.          fpbbs=popen("exec bbs > /dev/null","w");
  111.          if(!fpbbs) {
  112.            puts("cannot open bbs");
  113.            close(fdindex);
  114.            return 1;
  115.          }
  116.          fbbs=fopen("/tmp/bbs_tell","r"); 
  117.          fprintf(fpbbs,"SEND %s@%s <  %s\n",index.from,get_host_from_path(index.subject), 
  118.                        Myhostname); 
  119.      fprintf(fpbbs,"TELL-Response de %s\n",Myhostname);
  120.          fprintf(fpbbs,"%s response command: %s\n\n",Myhostname,
  121.                  get_cmd_from_path(index.subject));
  122.          while (!feof(fbbs)) {
  123.            fgets(buffer,sizeof(buffer),fbbs);
  124.            if (!strncmp(prompt,buffer,strlen(prompt))) {
  125.              strcpy(buf,&buffer[strlen(prompt)]);
  126.              strcpy(buffer,buf);
  127.            }  
  128.            fprintf(fpbbs,"%s",buffer);
  129.          }  
  130.          fprintf(fpbbs,"\nthank you, for your interest\n");
  131.          fprintf(fpbbs,"\n73 de %s\n",Myhostname);
  132.          fprintf(fpbbs,"***end\nDESTROY %d\nBYE\n",index.mesg); 
  133.          pclose(fpbbs); 
  134.          fclose(fbbs);
  135.          unlink("/tmp/bbs_tell"); 
  136.       }
  137.     }  
  138.   }
  139. stop:  
  140.   close(fdindex);
  141.   
  142.   return 0;
  143. }
  144.  
  145.